home *** CD-ROM | disk | FTP | other *** search
/ Celestin Apprentice 2 / Apprentice-Release2.iso / Source Code / C / Applications / MacGS 2.5.2ß3 / (MacGSLib.π) / macPrint.c < prev    next >
Encoding:
C/C++ Source or Header  |  1993-04-17  |  3.9 KB  |  224 lines  |  [TEXT/R*ch]

  1. /* Copyright (C) 1993 Aladdin Enterprises.  All rights reserved.
  2.    Distributed by Free Software Foundation, Inc.
  3.  
  4. This file is part of Ghostscript.
  5.  
  6. Ghostscript is distributed in the hope that it will be useful, but
  7. WITHOUT ANY WARRANTY.  No author or distributor accepts responsibility
  8. to anyone for the consequences of using it or for whether it serves any
  9. particular purpose or works at all, unless he says so in writing.  Refer
  10. to the Ghostscript General Public License for full details.
  11.  
  12. Everyone is granted permission to copy, modify and redistribute
  13. Ghostscript, but only under the conditions described in the Ghostscript
  14. General Public License.  A copy of this license is supposed to have been
  15. given to you along with Ghostscript so you can know your rights and
  16. responsibilities.  It should be in a file named COPYING.  Among other
  17. things, the copyright notice and this notice must be preserved on all
  18. copies.  */
  19.  
  20. #include <stdio.h>
  21. #include "macPrint.h"
  22.  
  23.  
  24. static THPrint    hPrint = (THPrint) NULL;
  25.  
  26. void            MacOpenPrint (void);
  27. void            MacClosePrint (void);
  28.  
  29.  
  30.     static void
  31. MacOpenPrint (void)
  32.  
  33. {
  34.     if (hPrint == (THPrint) NULL)
  35.     {
  36.         hPrint = (THPrint) NewHandle ((Size) sizeof (TPrint));
  37.  
  38.         if (hPrint /* != (THPrint) NULL */)
  39.         {
  40.             TGetRslBlk getRslBlk;
  41.  
  42.  
  43.             PrOpen ();
  44.  
  45.             PrintDefault (hPrint);
  46.  
  47.             getRslBlk.iOpCode = getRslDataOp;
  48.             PrGeneral ((Ptr) &getRslBlk);
  49.  
  50.             if (PrError () == noErr)
  51.             {
  52.             }
  53.         }
  54.     }
  55. }
  56.  
  57.  
  58.     static void
  59. MacClosePrint (void)
  60.  
  61. {
  62.     if (hPrint /* != (THPrint) NULL */)
  63.     {
  64.         DisposHandle ((Handle) hPrint);
  65.         hPrint == (THPrint) NULL;
  66.  
  67.         PrClose ();
  68.     }
  69. }
  70.  
  71.  
  72.     void
  73. MacDoPrStyleDlg (void)
  74.  
  75. {
  76.     MacOpenPrint ();
  77.  
  78.     InitCursor ();
  79.  
  80.     (void) PrStlDialog (hPrint);
  81. }
  82.  
  83.  
  84.     void
  85. MacPrintOnePage (PicHandle hPicture, Rect *pRect)
  86.  
  87. {
  88.     TPPrPort    hPrPort;
  89.  
  90.  
  91.     if (hPicture == (PicHandle) NULL || pRect == (Rect *) NULL)
  92.         goto premature_exit;
  93.  
  94.     MacOpenPrint ();
  95.  
  96.     InitCursor ();
  97.  
  98.     if (!PrJobDialog (hPrint))
  99.         goto premature_exit;
  100.  
  101.     if ((hPrPort = PrOpenDoc (hPrint, (TPPrPort) NULL, (Ptr) NULL))
  102.             /* != (TPPrPort) NULL */)
  103.     {
  104.         PrOpenPage (hPrPort, (Rect *) NULL);
  105.  
  106.         if (PrError () == noErr)
  107.             DrawPicture (hPicture, pRect);
  108.  
  109.         PrClosePage (hPrPort);
  110.     }
  111.  
  112.     PrCloseDoc (hPrPort);
  113.  
  114.     if ((*hPrint)->prJob.bJDocLoop == bSpoolLoop)
  115.     {
  116.         TPrStatus    prStatus;
  117.  
  118.  
  119.         PrPicFile (hPrint, (TPPrPort) NULL, (Ptr) NULL, (Ptr) NULL, &prStatus);
  120.     }
  121.  
  122. premature_exit:
  123.  
  124.     MacClosePrint ();
  125. }
  126.  
  127.  
  128.     OSErr
  129. MacGetRslData (TGetRslBlk *pGetRslBlk)
  130.  
  131. {
  132.     pGetRslBlk->iOpCode = getRslDataOp;
  133.     PrGeneral ((Ptr) pGetRslBlk);
  134.  
  135.     return PrError ();
  136. }
  137.  
  138.  
  139.     OSErr
  140. MacSetRslData (short iXRsl, short iYRsl)
  141.  
  142. {
  143.     TSetRslBlk    setRslBlk;
  144.  
  145.  
  146.     setRslBlk.iOpCode = setRslOp;
  147.     setRslBlk.hPrint  = hPrint;
  148.     setRslBlk.iXRsl      = iXRsl;
  149.     setRslBlk.iYRsl      = iYRsl;
  150.     PrGeneral ((Ptr) &setRslBlk);
  151.     (void) PrValidate (hPrint);
  152.  
  153.     return PrError ();
  154. }
  155.  
  156.  
  157.     void
  158. MacGetPrintRect (short iXRsl, short iYRsl, Rect *pRect)
  159.  
  160. {
  161.     Boolean    fHaveHPrint = (hPrint != (THPrint) NULL);
  162.  
  163.  
  164.     if (!fHaveHPrint)
  165.         MacOpenPrint ();
  166.  
  167.     if (hPrint /* != (THPrint) NIL */)
  168.     {
  169.         (void) MacSetRslData (iXRsl, iYRsl);
  170.         *pRect = (*hPrint)->prInfo.rPage;
  171.     }
  172.  
  173.     if (!fHaveHPrint)
  174.         MacClosePrint ();
  175. }
  176.  
  177.  
  178.     void
  179. MacPrintPages (short iXRsl, short iYRsl, PrintProcPtr pPrintProc)
  180.  
  181. {
  182.     TPPrPort    hPrPort;
  183.  
  184.  
  185.     MacOpenPrint ();
  186.  
  187.     InitCursor ();
  188.  
  189.     if (!PrJobDialog (hPrint) ||
  190.         MacSetRslData (iXRsl, iYRsl) /* != noErr */)
  191.         goto premature_exit;
  192.  
  193.     (void) (*pPrintProc) (iDoInitPrintDoc, &(*hPrint)->prJob);
  194.  
  195.     if ((hPrPort = PrOpenDoc (hPrint, (TPPrPort) NULL, (Ptr) NULL))
  196.             /* != (TPPrPort) NULL */)
  197.     {
  198.         while ((*pPrintProc) (iDoCheckThisPage))
  199.         {
  200.             PrOpenPage (hPrPort, (Rect *) NULL);
  201.  
  202.             if (PrError () == noErr)
  203.                 (void) (*pPrintProc) (iDoPrintThisPage);
  204.  
  205.             PrClosePage (hPrPort);
  206.         }
  207.     }
  208.  
  209.     PrCloseDoc (hPrPort);
  210.  
  211.     if ((*hPrint)->prJob.bJDocLoop == bSpoolLoop)
  212.     {
  213.         TPrStatus    prStatus;
  214.  
  215.  
  216.         PrPicFile (hPrint, (TPPrPort) NULL, (Ptr) NULL, (Ptr) NULL, &prStatus);
  217.     }
  218.  
  219. premature_exit:
  220.  
  221.     MacClosePrint ();
  222.     (void) MacSetRslData (0, 0);
  223. }
  224.